<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-node-edit" th:object="${node}">
			<input name="nodeId" type="hidden" th:field="*{nodeId}" />
			<input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label ">上级栏目：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="treeName" onclick="selectNodeTree()" readonly="true" th:field="*{parentName}"/>
				</div>
			</div>

			<!--<div class="form-group">
				<label class="col-sm-3 control-label ">数据模型：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="treeName" onclick="selectModeTree()" readonly="true" th:field="*{parentName}"/>
				</div>
			</div>-->

			<div class="form-group">
				<label class="col-sm-3 control-label">数据模型：</label>
				<div class="col-sm-8">
					<select id="cmsModelId" required name="cmsModelId" class="form-control select2-hidden-accessible">
						<option th:each="model:${models}" th:value="${model.fModelId}" th:text="${model.fName}" th:selected="${model.selected}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">栏目名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="node_name" th:field="*{node_name}" id="node_name">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">显示排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="orderNum" th:field="*{orderNum}">
				</div>
			</div>

			<div class="form-group hidden">
				<label class="col-sm-3 control-label">栏目状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script type="text/javascript">
		var prefix = ctx + "system/node";

		
		$("#form-node-edit").validate({
			rules:{
				node_name:{
					required:true,
					remote: {
		                url: prefix + "/checkNodeNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"nodeId": function() {
		                        return $("#nodeId").val();
		                    },
		                    "parentId": function() {
		                        return $("input[name='parentId']").val();
		                    },
		        			"node_name": function() {
		                        return $.common.trim($("#node_name").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				orderNum:{
					required:true,
					digits:true
				}
			},
			messages: {
		        "node_name": {
		            remote: "栏目已经存在"
		        }
		    }
		});

		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-node-edit').serialize());
	        }
	    }

		/*栏目管理-修改-选择栏目树*/
		function selectNodeTree() {
			var nodeId = $("#treeId").val();
			if(nodeId > 0) {
			    var options = {
					title: '栏目选择',
					width: "380",
					url: prefix + "/selectNodeTree/" + $("#treeId").val(),
					callBack: doSubmit
				};
				$.modal.openOptions(options);
			} else {
        		$.modal.alertError("父栏目不能选择");
        	}
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowLastLevel(tree)) {
	   			var body = layer.getChildFrame('body', index);
	   			$("#treeId").val(body.find('#treeId').val());
	   			$("#treeName").val(body.find('#treeName').val());
	   			layer.close(index);
			}
		}
	</script>
</body>
</html>
